package com.simple.core.config.mdc;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author FanXing
 * @date 2023年02月05日 18:13
 */
@Configuration
public class LogMDCFilterConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public FilterRegistrationBean servletRegistrationBean() {
        final FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        final LogMdcFilter log4jMDCFilterFilter = new LogMdcFilter(MDCConstant.REQUEST_ID_KEY, MDCConstant.REQUEST_ID_KEY, MDCConstant.REQUEST_ID_KEY);
        registrationBean.setFilter(log4jMDCFilterFilter);
        registrationBean.setOrder(2);
        return registrationBean;
    }
}
